import os

def remove_color_files(root_dir, img_exts=None):
    """
    删除所有目录及子目录下，文件名以 _color 结尾的图片文件。
    :param root_dir: 根目录路径
    :param img_exts: 图片扩展名列表（可选）
    """
    if img_exts is None:
        img_exts = ['.jpg', '.jpeg', '.png', '.webp', '.bmp']

    removed_count = 0
    for dirpath, _, filenames in os.walk(root_dir):
        for filename in filenames:
            name, ext = os.path.splitext(filename)
            if name.lower().endswith('_color') and ext.lower() in img_exts:
                file_path = os.path.join(dirpath, filename)
                try:
                    os.remove(file_path)
                    print(f"已删除: {file_path}")
                    removed_count += 1
                except Exception as e:
                    print(f"删除失败: {file_path}，原因: {e}")
    print(f"\n共删除 {removed_count} 个文件。")

if __name__ == "__main__":
    # 修改为你要处理的目录路径
    target_dir = r"E:\software\jmcomic_v1.2.6_windows_x64\jmcomic\cache\book"
    remove_color_files(target_dir)